package cn.xfdzx.android.apps.shop.adapter.remake;

import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.MyRemakeListMarketBean;
import cn.xfdzx.android.apps.shop.bean.ShopRemakeListMarketBean;
import cn.xfdzx.android.apps.shop.presenter.OrderRemakePresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.widget.CornerImageView;

/**
 * Creator: zf.
 * Date: 2020/9/15.
 * Description:订单评价商品列表适配器.-批发我的评价列表
 */
public class ShopRemake_MarketAdapter extends BaseQuickAdapter<ShopRemakeListMarketBean.DataBean.ReplyBean, BaseViewHolder>  {
    private OnItemOnClickListener onItemOnClickListener;
    private List<ShopRemakeListMarketBean.DataBean> data;

    public ShopRemake_MarketAdapter(@Nullable List<ShopRemakeListMarketBean.DataBean.ReplyBean> data) {
        super(R.layout.item_shopremake_market, data);
    }

    @Override
    public void setData(int index, @NonNull ShopRemakeListMarketBean.DataBean.ReplyBean data) {
        super.setData(index, data);
    }

    @Override
    protected void convert(final BaseViewHolder viewHolder, final ShopRemakeListMarketBean.DataBean.ReplyBean date) {
        TextView tv_remakecontent = viewHolder.getView(R.id.tv_remakecontent);//评价内容
        CornerImageView img_my = viewHolder.getView(R.id.img_my);
        img_my.setType(CornerImageView.TYPE_CIRCLE);
        ImageGlideUtil.loadImage(mContext,img_my,date.getUser().getAvatar());
        ImageView star01 = viewHolder.getView(R.id.star01);
        ImageView star02 = viewHolder.getView(R.id.star02);
        ImageView star03 = viewHolder.getView(R.id.star03);
        ImageView star04 = viewHolder.getView(R.id.star04);
        ImageView star05 = viewHolder.getView(R.id.star05);
        RecyclerView recycler_img = viewHolder.getView(R.id.recycler_img);

      //  Log.e("getPics",date.getPics().size()+"==角标"+viewHolder.getLayoutPosition());
        if (EmptyUtil.isNotEmpty(date.getPics())){
            recycler_img.setVisibility(View.VISIBLE);
            recycler_img.setLayoutManager(new GridLayoutManager(mContext,3));
            OrderMyRemake_RetailImageListAdapter imageListAdapter = new OrderMyRemake_RetailImageListAdapter(date.getPics());
            recycler_img.setAdapter(imageListAdapter);
        }else {
            recycler_img.setVisibility(View.GONE);
        }


        if (EmptyUtil.isNotEmpty(date.getComment())){
            tv_remakecontent.setVisibility(View.VISIBLE);
            tv_remakecontent.setText(date.getComment());
        }else {
            tv_remakecontent.setVisibility(View.GONE);
        }

        clearState(star01,star02,star03,star04,star05,date.getService_score()+"");
        if (EmptyUtil.isNotEmpty(date.getGoods_unit())){
            viewHolder.setText(R.id.tv_goodscount,"数量: "+date.getGoods_num()+" 规格: "+date.getGoods_unit()
                    +"("+date.getGoods_name()+")")
                    .setText(R.id.tv_time,date.getCreated_at())
                    .setText(R.id.tv_nickname,date.getUser().getNickname()==null?"":date.getUser().getNickname());
        }else {
            viewHolder.setText(R.id.tv_goodscount,"数量: "+date.getGoods_num() +"("+date.getGoods_name()+")")
                    .setText(R.id.tv_time,date.getCreated_at())
                    .setText(R.id.tv_nickname,date.getUser().getNickname()==null?"":date.getUser().getNickname());
        }

       //

    }

    private void clearState(ImageView star01, ImageView star02, ImageView star03, ImageView star04, ImageView star05,String starnum) {
        star01.setVisibility(View.GONE);
        star02.setVisibility(View.GONE);
        star03.setVisibility(View.GONE);
        star04.setVisibility(View.GONE);
        star05.setVisibility(View.GONE);

        switch (starnum){
            case "1":
                star01.setVisibility(View.VISIBLE);
                break;
            case "2":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                break;
            case "3":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                star03.setVisibility(View.VISIBLE);
                break;
            case "4":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                star03.setVisibility(View.VISIBLE);
                star04.setVisibility(View.VISIBLE);
                break;
            case "5":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                star03.setVisibility(View.VISIBLE);
                star04.setVisibility(View.VISIBLE);
                star05.setVisibility(View.VISIBLE);
                break;
        }
    }

    private void setDrawableLeft(TextView tv_cai,Drawable drawable) {
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv_cai.setCompoundDrawables(drawable, null, null, null);
    }

    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<ShopRemakeListMarketBean.DataBean.ReplyBean> list){
        super.replaceData(list);
    }

    public void setItemDeleteClickListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemOnClick(int position, ShopRemakeListMarketBean.DataBean.ReplyBean date);
    }

}
